package me.cjj.android.assignment

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_result.*

class ResultActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_result)
        val correctResult = intent.extras.get("correct_result") as BooleanArray
        val timeCost = intent.extras.get("time_cost") as LongArray
        val averageLinear = (longArrayOf(timeCost[0], timeCost[1], timeCost[2], timeCost[3], timeCost[4]).average() / 1000)
        val averageQuadratic = longArrayOf(timeCost[5], timeCost[6], timeCost[7], timeCost[8], timeCost[9]).average() / 1000
        var i = 0
        correctResult.map { b -> if (b) i++ }
        tvResult.text = "Correct answer:$i\nThe average time cost of linear equation is $averageLinear second\nThe average time cost of quadratic equation is $averageQuadratic second"
    }
}
